/**
 * @author Chris Lewis Jan 31, 2007 <chris@thegodcode.net>
 * @version $Id: ImageSetBuilder.js 53 2008-01-31 22:30:42Z burningodzilla $
 */

var ImageSetPanels = Class.create();
ImageSetPanels.prototype = {
	
	initialize: function(e) {
		this.panels = $$('.oln-image-piece');
	},
	
	makeAvailable: function(count) {
		//TODO
		var _counter = 1;
		this.panels.each(
			function(panel) {
				if(_counter <= count) {
					if(! panel.visible()) {
						Effect.Appear(panel, { duration: 0.5 });
					}
				} else {
					Effect.Fade(panel, { duration: 0.5 });
				}
				_counter++;
			}
		)
	}
	
}

//brrt
Event.observe(window, 'load',
	function() {
		//init the panel mgr and attach handler to select box
		FIXME = new ImageSetPanels();
		Event.observe($('imageCountChooser'), 'change',
			function() {
				FIXME.makeAvailable(this.selectedIndex);
			}
		);
		
		$$('.oln-image-piece').each(
			function(e) {
				var preview = e.select('.oln-image-preview')[0];
				Event.observe(e.select('.oln-image-url')[0], 'blur',
					function() {
						var bg = this.value;
						preview.setStyle({background: 'url(' + bg + ')'});
						//window.open(this.value);
					}
				);
			}
		);
	}
);